<template>
  <el-row>
    <el-form :model="form"
             label-width="80px"
             :rules="rules"
             ref="form">
      <el-col :span="24">
        <el-form-item label="组织编码"
                      prop="build_org">
          <el-input v-model="form.build_org"
                    placeholder="请输入组织编码"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="24"
              class="box-style">
        <el-button size="medium"
                   type="primary"
                   @click="onSave('form')">保存</el-button>
        <el-button size="medium"
                   @click="onBack">取消</el-button>
      </el-col>
    </el-form>
  </el-row>
</template>
<script>
import { SendCodeApi } from '@/services/Public'
export default {
  props: {
    todos: Number,
    catchSave: Function,
    catchBack: Function
  },
  data () {
    return {
      form: {
        build_org: ''
      },
      rules: {
        build_org: [
          { required: true, message: '组织编码不能为空', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    //保存
    onSave (data) {
      this.$refs[data].validate((valid) => {
        if (valid) {
          SendCodeApi.addJoin({
            data: {
              company_name: '',
              organization_type: ''
            }
          }).then((res) => {
            this.catchSave('建立组织');
          }).catch((error) => {
            console.log(error)
          })

        } else {
          console.log('error')
        }
      })
    },
    //取消
    onBack () {
      this.catchBack('建立组织')
    }
  },
  watch: {
    todos (n, o) {
      console.log('watch-todos=', n)
    }
  },
  created () {
    console.log('created-todos=', this.todos)
  }
}
</script>

<style lang="scss" scoped>
.box-style {
  margin-top: 20px;
  text-align: center;
}
</style>